//
//  SupermarketViewController.m
//  AffectionBee
//
//  Created by 李通 on 16/8/18.
//  Copyright © 2016年 chivalrous. All rights reserved.
//

#import "SupermarketViewController.h"
#import "TapTableView.h"
#import "ProductTableView.h"
#import "TabModel.h"
#import "ProductModel.h"
#import "UIViewController+ImageViewAniamtion.h"


#define SCREENSIZE [UIScreen mainScreen].bounds.size
@interface SupermarketViewController ()

@property(nonatomic,weak)TapTableView*tap;
@property(nonatomic,weak)ProductTableView *product;
@property(nonatomic,copy)NSArray<TabModel*> *modelList;


@end

@implementation SupermarketViewController
- (void)viewDidLoad
{
    [super viewDidLoad];

    
    
    [self setupUI];
    
    
    
    
    [TabModel modelListWithUrlStr:@"http://iosapi.itcast.cn/loveBeen/supermarket.json.php" parameters:@{@"call":@(5)} SuccessBlock:^(NSArray<TabModel *> *modelList) {
        
        
        self.modelList = modelList;
        
        
        
        self.tap.array = modelList;
        
        self.product.tabArray = modelList;
        
        
    } failure:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        NSLog(@"获取数据失败");
        
    }];
    
    
    //接收来自cell的图片动画通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cellImageViewAniamte:) name:@"CellImageAnimate" object:nil];
    
    //[self setupUI];

}


-(void)setupUI
{
    //分类的tableView
    TapTableView * tap = [[TapTableView alloc]initWithFrame:CGRectMake(0, 0, SCREENSIZE.width*0.25,SCREENSIZE.height)];
    
    self.tap = tap;
    
    

    //产品的tableView
    ProductTableView* product = [[ProductTableView alloc]initWithFrame:CGRectMake(SCREENSIZE.width*0.25, 64, SCREENSIZE.width*0.75,SCREENSIZE.height)];
    self.product = product;
    
    
    
    [self.view addSubview:tap];
    [self.view addSubview:product];
}

//处理动画通知
-(void)cellImageViewAniamte:(NSNotification*)noti
{
    UIImageView *cellImageView = (UIImageView *)noti.object;
    
    //开启动画效果
    [self addProaddProductsAnimation:cellImageView];
}

//移除通知
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
